{layout name="formlayout" /}

<div class="layui-form" lay-filter="layuiadmin-form-useradmin" id="layuiadmin-form-useradmin" style="padding: 20px">
    <div class="layui-form-item">
        <label class="layui-form-label">文章标题</label>
        <div class="layui-input-block">
            <input type="text" name="title" value="{$item.title}" lay-verify="required" placeholder="请输入文章标题"
                   autocomplete="off" class="layui-input">
        </div>
    </div>
    <!--<div class="layui-form-item">-->
    <!--<label class="layui-form-label">分类</label>-->
    <!--<div class="layui-input-block">-->
    <!--<select name="cateId" lay-verify="required">-->
    <!--<option value=""></option>-->
    <!--{volist name="cates" id="val"}-->
    <!--<option value="{$val.id}" {if ($val.id==$item.cateId)} selected{/if}>{$val.name}</option>-->
    <!--{/volist}-->
    <!--</select>-->
    <!--</div>-->
    <!--</div>-->
    <div class="layui-form-item">
        <label for="" class="layui-form-label">文章内容</label>
        <div class="layui-input-block">
            <script id="detail" name="detail" type="text/plain"></script>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">图片</label>
        <div class="layui-input-inline">
            <input type="text" id="phy" name="phy" value="{$item.phy|default=''}" lay-verify="required" placeholder="请上传图片"
                   autocomplete="off" class="layui-input">
            <div class="layui-upload-list">
                <img class="layui-upload-img" id="demo1" src="{$item.phy|default=''}">
                <p id="demoText"></p>
            </div>
        </div>
        <button style="float: left;" type="button" class="layui-btn" id="layuiadmin-upload-case">上传图片</button>
    </div>
    <!--<div class="layui-form-item">-->
    <!--<label class="layui-form-label">排序</label>-->
    <!--<div class="layui-input-block">-->
    <!--<input type="text" name="order" value="{$item.order|default=100}" lay-verify="required"-->
    <!--autocomplete="off" class="layui-input">-->
    <!--</div>-->
    <!--</div>-->
    <div class="layui-form-item layui-hide">
        <input type="hidden" name="id" value="{$item.id}">
        <input type="button" lay-submit lay-filter="zbc-case-submit" id="zbc-case-submit" value="确认">
    </div>
</div>
<!-- 配置文件 -->
<script type="text/javascript" src="/ue/ueditor.config.js"></script>
<!-- 编辑器源码文件 -->
<script type="text/javascript" src="/ue/ueditor.all.js"></script>
<script>
    layui.config({
        base: '/static/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['laydate','index', 'form','upload'], function () {
        var $ = layui.$
            , form = layui.form
            , laydate = layui.laydate
            , upload = layui.upload;
        $(function () {
            window.ue = UE.getEditor('detail');
            ue.ready(function(){
                ue.setContent('{$item.detail|raw}')
            })
        });

        laydate.render({
            elem: '#pubdate',
            type: 'datetime'
        });

        upload.render({
            elem: '#layuiadmin-upload-case'
            , url: '/admin/upload/image?type=case'
            , accept: 'images'
            , method: 'post'
            , acceptMime: 'image/*'
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#demo1').attr('src', result); //图片链接（base64）
                });
            }
            , done: function (res) {
                //$(this.item).prev("div").children("input").val(res.data.src)
                //console.log(res);
                if(!res.data)
                    return layer.msg('上传失败');
                else
                    $("#phy").val(res.data.src);
            }
        });
    });
</script>